package com.jt.tenant.util;

import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Build;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;

/**
 * Created by 马长鸣 on 2016/5/9.
 */
public class UtilPermission {

    public static void Permission(Activity acitivty, String... permission) {

        for(int i = 0 ; i < permission.length ; i++){

            Permission(acitivty, permission[i]);

        }

    }

    public static void Permission(Activity acitivty, String permission){

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

            if (PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(acitivty, permission)) {

                return;

            } else {

                if (ContextCompat.checkSelfPermission(acitivty, permission) != PackageManager.PERMISSION_GRANTED) {

                    if (!ActivityCompat.shouldShowRequestPermissionRationale(acitivty, permission)) {

                        ActivityCompat.requestPermissions(acitivty, new String[]{ permission }, 0);

                    }

                }

            }

        }

    }

}
